package com.aaa.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author Administrator
 * 发送邮件的工具类
 */
@Component
public class EmailUtil {
    @Autowired
    private JavaMailSender mailSender;

    public static EmailUtil emailUtil;
    @PostConstruct
    public void init(){
        emailUtil = this;
        emailUtil.mailSender = this.mailSender;
    }
    /*public static String getEmailCode(JavaMailSender mailSender,String toEmail){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("928351068@qq.com");
        message.setTo(toEmail);
        message.setSubject("高校共享电瓶");
        String code = RandomUtil.getRandom();
        message.setText("尊敬的高校共享电瓶用户:"+",您的验证码为:"+code);
        emailUtil.mailSender.send(message);
        return code;
    }*/
    public static String getEmailCode(String toEmail){
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom("928351068@qq.com");
        message.setTo(toEmail);
        message.setSubject("高校共享电瓶");
        String code = RandomUtil.getRandom();
        message.setText("尊敬的高校共享电瓶用户:"+",您的验证码为:"+code);
        emailUtil.mailSender.send(message);
        return code;
    }

}
